<template>
	<view class="home-container">
		<!-- 顶部搜索区域 -->
		<view class="search-box" :class="{left:isLeft}">
			<icon size="20" type="search"></icon>
			<input @focus="isLeft=true" @blur="isLeft=false" type="text" placeholder="搜索" />
		</view>
		<!-- 轮播图区域 -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" circular="true">
			<swiper-item v-for="item in swiperList" :key="item.goods_id">
				<image class='swiper-img' :src="item.image_src"></image>
			</swiper-item>
		</swiper>
		<!-- 导航区域 -->
		<view class="nav-box">
			<navigator v-for="(item ,index) in navList" :key="index">
				<image :src="item.image_src" mode=""></image>
			</navigator>
		</view>
		<!-- 楼层区域 -->

		<view class="floor-container">
			<view class="floor-item" v-for="(item,index) in floorList" :key='index'>
				<image class='title-img' :src="item.floor_title.image_src" mode=""></image>
				<view class="bottom-box">
					<view class="left">
						<image :src="item.product_list[0].image_src" mode=""></image>
					</view>
					<view class="right">
						<template v-for="(item,index) in item.product_list">
							<image v-if="index!==0" :src="item.image_src" mode=""></image>
						</template>

					</view>
				</view>
			</view>
		</view>
		<!-- 返回顶部 -->
		<view class="top" v-if="isShow" @tap="toTop">
			<view>^</view>
			顶部
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isLeft: false,
				swiperList: [],
				navList: [],
				floorList: [],
				isShow: false
			}
		},
		methods: {
			toTop() {
				uni.pageScrollTo({
					scrollTop:0
				})
			}
		},
		onLoad() {
			/* uni.request({
				url:'https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata',
				method:"GET",
				
			}).then(res=>{
				console.log(res)
				this.swiperList=res[1].data.message
			}) */
			this.$request({
				url: '/home/swiperdata',
				method: 'get'
			}).then(res => {
				console.log(res)
				this.swiperList = res.data.message
			})
			//导航区域
			this.$request({
				url: '/home/catitems',
				method: 'get'
			}).then(res => {
				console.log(res)
				this.navList = res.data.message
			})
			//导航区域
			this.$request({
				url: '/home/floordata',
				method: 'get'
			}).then(res => {
				console.log(res)
				this.floorList = res.data.message
			})
		},
		onPageScroll(e) {
			if (e.scrollTop >= 200) {
				this.isShow = true
			} else {
				this.isShow = false
			}
		},
	
	}
</script>

<style lang="less">
	page {}

	.home-container {
		.floor-container {
			.floor-item {
				.title-img {
					height: 80rpx;
				}

				.bottom-box {
					padding: 20rpx 17rpx;
					padding-right: 0;
					display: flex;

					image {
						width: 232rpx;
					}

					.left {
						image {
							height: 386rpx;
						}

						margin-right: 10rpx;
					}

					.right {
						image {
							height: 188rpx;

							margin-right: 10rpx;
						}
					}
				}
			}
		}

		.top {
			width: 90rpx;
			height: 90rpx;
			text-align: center;
			display: flex;
			flex-direction: column;
			border-radius: 50%;
			background-color: #ccc;
			position: fixed;
			right: 17rpx;
			bottom: 40rpx;
			opacity: .5;
		}

		.search-box {
			background-color: #fe2c4b;
			padding: 16rpx;
			position: relative;

			input {
				background-color: white;
				border-radius: 10rpx;
				height: 60rpx;
				padding-left: 360rpx;
				transition: .5s;
			}

			icon {
				position: absolute;
				left: 330rpx;
				top: 28rpx;
				transition: .5s;
			}

			// 解析完 才会编程 .search-box.left
			&.left {
				input {
					padding-left: 45rpx;
				}

				icon {
					left: 20rpx;
				}
			}
		}

		.swiper-img {
			display: block;
			width: 100%;
			height: 340rpx;
		}

		.nav-box {
			display: flex;
			height: 194rpx;
			align-items: center;

			navigator {
				flex: 1;
				text-align: center;

				image {
					height: 140rpx;
					width: 128rpx;
				}
			}
		}

	}
</style>
